﻿package export.mapPrefab.trap
{
	import base.BaseAddEffect;
	import base.BaseHero;
	
	import com.dusk.tool.HitTest;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.geom.*;
	
	public class FireThron extends MovieClip
	{
		
		public function FireThron()
		{
			super();
			this.addFrameScript(0, this.frame1);
			this.gc = Config.getIns();
		}
		
		public var isFireThron:MovieClip;
		private var attackId:uint = 0;
		private var gc:Config;
		private var intervalCount:uint = 0;
		
		public function step():void
		{
			var _loc1_:Boolean = false;
			var _loc2_:* = BaseHero;
			if (this.intervalCount == 0)
			{
				
				this.intervalCount = Number(this.gc.frameClips) * 2;
			}
			if (this.intervalCount >= 0)
			{
				--this.intervalCount;
			}
			if (this.currentFrame == 1)
			{
				_loc1_ = false;
				if (this.gc.hero1)
				{
					if (Math.abs(this.x - Number(this.gc.hero1.x)) <= 200)
					{
						_loc1_ = true;
					}
				}
				if (!_loc1_)
				{
					if (this.gc.hero2)
					{
						if (Math.abs(this.x - Number(this.gc.hero2.x)) <= 200)
						{
							_loc1_ = true;
						}
					}
				}
				if (_loc1_)
				{
					this.gotoAndPlay(2);
				}
			}
			if (this.currentFrame >= 2 && this.currentFrame <= 19)
			{
				for each (_loc2_ in this.gc.team.getHeroArray())
				{
					if (_loc2_.beAttackIdArray.indexOf(this.getAttackId()) == -1)
					{
						if (!_loc2_.isInvincible())
						{
							if (HitTest.complexHitTestObject(this, _loc2_.colipse))
							{
								_loc2_.reduceHp(45 + (Math.random() - 0.5) * 10, true);
								_loc2_.addCurAddEffect([{
									"name": BaseAddEffect.FIRE,
									"time": gc.frameClips * 3,
									"hurt": BaseHero(_loc2_).getHpMax() * 0.05
								}]);
								if (_loc2_.getBBDC().getDirect() == 0)
								{
									_loc2_.setAttackBack(new Point(10, 0));
								}
								else
								{
									_loc2_.setAttackBack(new Point(-10, 0));
								}
								_loc2_.beAttackIdArray.push(this.getAttackId());
								_loc2_.beAttackDoing();
							}
						}
					}
				}
			}
		}
		
		private function frame1():void
		{
			stop();
		}
		
		private function getAttackId():String
		{
			return this.name + this.attackId;
		}
		
		private function newAttackId():void
		{
			++this.attackId;
		}
	}
}
